package esgi.stationratp.dal;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 
 * @author Ahmed
 * 
 */
public class StationDatabase extends SQLiteOpenHelper {

	private static final String STATION_TABLE_NAME = "Satations";
	private static final String COL_ID = "ID";
	private static final String COL_NAME = "NAME";
	private static final String COL_TOWN = "TOWN";
	private static final String COL_X = "X";
	private static final String COL_Y = "Y";
	private static final String COL_RESEAU = "RESEAU";

	public StationDatabase(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

		StringBuilder create = new StringBuilder();
		create.append("CREATE TABLE " + STATION_TABLE_NAME);
		create.append(" (");
		create.append(" " + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ");
		create.append(" " + COL_NAME + " TEXT, ");
		create.append(" " + COL_TOWN + " TEXT, ");
		create.append(" " + COL_X + " REAL, ");
		create.append(" " + COL_Y + " REAL, ");
		create.append(" " + COL_RESEAU + " TEXT ");
		create.append(" );");

		db.execSQL(create.toString());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + STATION_TABLE_NAME + " ;");
		onCreate(db);
	}
}
